package com.lee.wordcount;

import com.lee.util.HadoopUtil;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class Driver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        // 1 init
        Configuration conf = HadoopUtil.getConfiguration();

        System.setProperty("HADOOP_USER_NAME", "hadoop");

        Job job = Job.getInstance(conf);
        job.setJarByClass(Driver.class);

        // 2 设置mapreduce
        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReduce.class);

        // 3 设置mapper和reduce的输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        // 4设置输入和输出路径
        FileInputFormat.setInputPaths(job, HadoopUtil.getHdfsPath("/wc"));
        FileOutputFormat.setOutputPath(job, HadoopUtil.getHdfsPath("/out02"));

        job.waitForCompletion(true);
    }
}
